package com.woniuxy.springbootmybatis.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author linke
 * @version 1.0
 * @className: SwaggerConfig
 * @description: Swagger 配置类
 * @date 2021/11/17 1:51
 */
@Configuration
@EnableSwagger2//开启swagger
public class SwaggerConfig {
    //1.配置应用程序说明：对当前应用简单描述
    @Bean
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("商品模块API文档")//xx项目接口文档
                .description("采用restful风格接口")//该文档对xx项目做了xxx描述
                .version("1.0")//接口文档版本 1。0
                .build();//构建
    }
    //2.指定为项目那些接口生成接口文档
    @Bean
    public Docket docket(ApiInfo apiInfo) {
        return new Docket(DocumentationType.SWAGGER_2)//文档版本格式
                .apiInfo(apiInfo)
                .select()
                .apis(RequestHandlerSelectors.basePackage(
                        "com.woniuxy.springbootmybatis.controller"))
                .apis(RequestHandlerSelectors.any())//选择所有的controller
                .paths(PathSelectors.any())//选择所有的路径
                .build();
    }
}